# https://www.tcpdump.org/release/tcpdump-4.99.5.tar.gz
# https://www.tcpdump.org/release/libpcap-1.10.5.tar.gz
# Libpcap可用configure脚本和make构建也可以使用CMake和CMake支持的任何构建系统构建
#FROM debian:12.11-slim
FROM m.daocloud.io/docker.io/library/debian:12.11-slim
ENV TZ Asia/Shanghai
ADD libpcap-1.10.5.tar.gz tcpdump-4.99.5.tar.gz /usr/local/tcpdump4.99.5-libpcap1.10.5/
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources  && \
apt update && apt install -y build-essential  flex bison && \
# 编译libpcap==================================================================================
# https://github.com/the-tcpdump-group/libpcap/blob/master/INSTALL.md
# 运行./configure从Makefile.in生成Makefile
# ./configure --help
# 编译libpcap需要安装flex和bison
cd /usr/local/tcpdump4.99.5-libpcap1.10.5/libpcap-1.10.5 && \
./configure && \
make -j 8 && \
#只构建tcpdump不需要安装libpcap/只需确保tcpdump和libpcap目录树具有相同父目录
# 编译libpcap==================================================================================
# 编译tcpdump==================================================================================
# https://github.com/the-tcpdump-group/tcpdump/blob/master/INSTALL.md
# 如果尚未构建libpcap/未安装libpcap，请先安装libpcap
# 构建libpcap后使用make install安装或确保libpcap和tcpdump源代码树位于同一目录
cd /usr/local/tcpdump4.99.5-libpcap1.10.5/tcpdump-4.99.5 && \
./configure && \
make -j8 && make install && \
# 从源代码构建tcpdump通常会将二进制文件安装为/usr/local/bin/tcpdump
# 编译tcpdump==================================================================================
rm -rf /usr/local/tcpdump4.99.5-libpcap1.10.5 && \
apt purge -y build-essential  flex bison && \
rm -rf /var/lib/apt/lists/*
CMD ["tcpdump","--version"]

# docker build -t registry.cn-hangzhou.aliyuncs.com/xiaoyilin/tcpdump:4.99.5 .
# docker run -it --rm registry.cn-hangzhou.aliyuncs.com/xiaoyilin/tcpdump:4.99.5 bash
# docker run --rm registry.cn-hangzhou.aliyuncs.com/xiaoyilin/tcpdump:4.99.5
# dokcer push registry.cn-hangzhou.aliyuncs.com/xiaoyilin/tcpdump:4.99.5